/**
 * Description: 服务接口
 *
 * @author      Eden
 * @datetime    2016/12/7 20:56
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */

(function () {

    "use strict";

    var api = {
        getConfigUrl: "/system/service/getConfig",
        saveConfigUrl: "/system/service/saveConfig"
    };

    sm.controller('admin-system-api-controller', ['$scope', '$http', 'Modal', function ($scope, $http, Modal) {

        $scope.api = {
            service: {
                luosimao: "",
                aliExpress: ""
            },
            stream: {
                appKey: "",
                appSecret: ""
            },
            qq: {
                qqAppId: "",
                qqAppSecret: ""
            },
            wechat: {
                wechatAppId: "",
                wechatAppSecret: "",
                wechatCssUrl: ""
            }
        };


        $http.get(api.getConfigUrl).success(function (res) {
            if (res) {
                var data = res.data;
                angular.forEach(data, function (val, key) {
                    $scope.api[key] = val;
                });
            }
        });

        $scope.saveApis = function (key) {
            if (!$scope.api[key]) {
                return false;
            }

            $http.post(api.saveConfigUrl + '?key=' + key, $scope.api[key]).success(function (res) {
                if (res.state) {
                    Modal.success('设置成功');
                } else {
                    var err = res.err ? res.err : '设置失败';
                    Modal.error(err);
                }
            });
        };



    }]);

})();